#include <iostream>
#include <string>
#include <cmath>
using namespace std;

bool simple(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    string input;
    getline(cin, input);
    string words[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int numbers[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int c = 0;

    string num_str = "";
    for (int i = 0; i < input.length(); i++) {
        if (input[i] != ' ') {
            num_str += input[i];
        } else {
            for (int j = 0; j < 10; j++) {
                if (num_str == words[j]) {
                    c = c * 10 + numbers[j];
                    break;
                }
            }
            num_str = "";
        }
    }
    for (int j = 0; j < 10; j++) {
            if (num_str == words[j]) {
                c = c * 10 + numbers[j];
                break;
            }
    }

    cout << c;
    if (c > 1000 || c < 10) {
        cout << "wrong input" << endl;
    } 
    else {
        int closest1 = c;
        int closest2 = c;
        while (true) {
            if (simple(closest1)) {
                closest1  = closest1;
                break;
            }
            closest1++;
        }
        while (true) {
            if (simple(closest2)) {
                closest2  = closest2;
                break;
            }
            closest2--;
        }
        if ((closest1 - c) <= (c - closest2)){
            cout << closest1;
        }
        else{
            cout << closest2;
        }

    }


    return 0;
}
